<?php

class Default_VpagesController extends ExtLb_Controller_Action
{
	private $postTbl;
	private $commentTbl;

    public function init(){
        $this->loadCss('default', 'vpages', FOLDER_ROOT_NAME);

        $this->postTbl	= new Admin_Model_Posts();
        $this->commentTbl = new Admin_Model_Comments();
        
        //RANDOM POST (BAI VIET NOI BAT)
    	$randPost = $this->postTbl->selectPost('bv.trangThai = 1','baiVietId DESC',10)->query()->fetchAll();
    	$this->view->randPosts = $randPost;
    	
    	$this->view->comments = $this->commentTbl->selectComment(NULL,'yKienId DESC',5)->query()->fetchAll();
    }
    
    public function indexAction()
    {
    	if (isset($_GET['vp']) && !empty($_GET['vp'])){
    		$selectPost = $this->postTbl->selectPost('bv.trangThai = 1 and bv.menu2Id ='.$_GET['vp']);
    		$paginatorPosts = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($selectPost));
    		$paginatorPosts->setItemCountPerPage(10)
    					->setPageRange(3)
    					->setCurrentPageNumber($this->_getParam('page',1));
    							
    		$this->view->paginatorPosts = $paginatorPosts;
    		
    	}elseif (isset($_GET['gt']) && !empty($_GET['gt'])){
    		//SET DEFAUL MUC GIOI THIEU CO VALUE= 0 MAC DU TRONG Db = 2
    		$selectPost = $this->postTbl->selectPost('bv.trangThai = 1 and bv.menu2Id =0');
    		$paginatorPosts = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($selectPost));
    		$paginatorPosts->setItemCountPerPage(10)
    					->setPageRange(3)
    					->setCurrentPageNumber($this->_getParam('page',1));
    							
    		$this->view->paginatorPosts = $paginatorPosts;
    	}else{
    		$this->_redirect('default/index');
    	}
    	
    }


}

